﻿namespace TestTool.GUI.Controls
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;
    using TestTool.GUI.Controllers;
    using TestTool.GUI.Data;
    using TestTool.GUI.Enums;
    using TestTool.GUI.Properties;
    using TestTool.GUI.Utils;
    using TestTool.GUI.Views;
    using TestTool.Tests.Definitions.Data;
    using TestTool.Tests.Definitions.Trace;

    internal class ConformanceTestPage : Page, IConformanceTestView, IView
    {
        private ConformanceTestController _controller;
        private bool _docEnabled;
        private bool _isReportGeneratorsEnabled;
        private bool _reportEnabled;
        private bool _testRunning;
        private Button btnClear;
        private Button btnClearDeviceInformation;
        private Button btnClearMemberInfo;
        private Button btnDatasheetReport;
        private Button btnDoCReport;
        private Button btnReport;
        private Button btnRun;
        private IContainer components;
        private GroupBox gbDutInformation;
        private GroupBox gbResponsible;
        private GroupBox gbRunTest;
        private GroupBox gbTestExecutionInformation;
        private Label lblBrand;
        private Label lblMemberAddress;
        private Label lblMemberName;
        private Label lblModel;
        private Label lblOperatorName;
        private Label lblOrganizationAddress;
        private Label lblOrganizationName;
        private Label lblOtherInformation;
        private Label lblproductName;
        private Label lblProgress;
        private Label lblTestExecutionMessage;
        private ProgressBar pbTestsExecution;
        private ToolTip setupPageToolTip;
        private TextBox tbBrand;
        private TextBox tbLog;
        private TextBox tbMemberAddress;
        private TextBox tbMemberName;
        private TextBox tbModel;
        private TextBox tbOperatorName;
        private TextBox tbOrganizationAddress;
        private TextBox tbOrganizationName;
        private TextBox tbOtherInformation;
        private TextBox tbProductName;

        public ConformanceTestPage()
        {
            this.InitializeComponent();
            this.pbTestsExecution.Visible = false;
            this._controller = new ConformanceTestController(this);
            this._controller.DeviceInformationReceived += new ManagementServiceProvider.DeviceInformationReceived(this.OnDeviceInformationReceived);
        }

        public void BeginTest(TestInfo testInfo)
        {
            Action method = null;
            Action action2 = null;
            if (string.IsNullOrEmpty(testInfo.Id))
            {
                if (method == null)
                {
                    method = () => this.lblTestExecutionMessage.Text = testInfo.Name + " - process started";
                }
                base.BeginInvoke(method);
            }
            else
            {
                if (action2 == null)
                {
                    action2 = () => this.lblTestExecutionMessage.Text = testInfo.Name + " - test started";
                }
                base.BeginInvoke(action2);
            }
        }

        public void BeginTests()
        {
            this.pbTestsExecution.Visible = true;
            this.IsReportGeneratorsEnabled = false;
            this.btnDoCReport.Enabled = false;
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            this.tbOperatorName.Clear();
            this.tbOrganizationName.Clear();
            this.tbOrganizationAddress.Clear();
        }

        private void btnClearDeviceInformation_Click(object sender, EventArgs e)
        {
            this.tbProductName.Clear();
            this.tbBrand.Clear();
            this.tbModel.Clear();
            this.tbOtherInformation.Clear();
        }

        private void btnClearMemberInfo_Click(object sender, EventArgs e)
        {
            this.tbMemberName.Clear();
            this.tbMemberAddress.Clear();
        }

        private void btnDatasheetReport_Click(object sender, EventArgs e)
        {
            string str;
            if (this.TryToGetPdfFileName("xml", "Xml document |*.xml", out str))
            {
                this.Controller.CreateDatasheetReport(str);
            }
        }

        private void btnDoCReport_Click(object sender, EventArgs e)
        {
            string str;
            if (this.ValidateFields() && this.TryToGetPdfFileName("pdf", "PDF Document |*.pdf", out str))
            {
                this.Controller.CreateDoCReport(str);
            }
        }

        private void btnReport_Click(object sender, EventArgs e)
        {
            string str;
            if (this.ValidateFields() && this.TryToGetPdfFileName("pdf", "PDF Document |*.pdf", out str))
            {
                this.Controller.CreateReport(str);
            }
        }

        private void btnRun_Click(object sender, EventArgs e)
        {
            if (!this._testRunning)
            {
                if (!this.ValidateTestSettings())
                {
                    this._controller.RaiseSettingsMissing(new List<string> { "EventTopic" });
                    return;
                }
                this.btnRun.Text = "Stop";
                this.btnRun.Image = Resources.Stop;
                this.pbTestsExecution.Value = 0;
                this.lblProgress.Text = string.Empty;
                this.pbTestsExecution.Style = ProgressBarStyle.Marquee;
                this._controller.RunAll();
            }
            else
            {
                this.lblTestExecutionMessage.Text = "Stop tests execution...";
                this.btnRun.Enabled = false;
                this._controller.Halt();
            }
            this._testRunning = !this._testRunning;
        }

        public void ClearInfo()
        {
            base.BeginInvoke((Action)delegate
            {
                this.pbTestsExecution.Value = 0;
                this.lblProgress.Text = string.Empty;
                this.lblTestExecutionMessage.Text = string.Empty;
            });
        }

        public void ClearLog()
        {
            base.BeginInvoke(new Action(() => this.tbLog.Clear()));
        }

        public void DefineTestsCount(int total)
        {
            base.BeginInvoke((Action)delegate
            {
                this.pbTestsExecution.Style = ProgressBarStyle.Blocks;
                this.pbTestsExecution.Minimum = 0;
                this.pbTestsExecution.Maximum = total;
            });
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        public void EnableControls(bool enable)
        {
            this.IsReportGeneratorsEnabled = this._reportEnabled && enable;
            this.btnDoCReport.Enabled = this._docEnabled && enable;
            this.btnRun.Enabled = enable;
        }

        public void EnableGenerateDoc(bool bEnable)
        {
            this._docEnabled = bEnable;
            base.BeginInvoke(new Action(() => this.btnDoCReport.Enabled = bEnable));
        }

        public void EnableSaveReport(bool bEnable)
        {
            this._reportEnabled = bEnable;
            base.BeginInvoke(new Action(() => this.IsReportGeneratorsEnabled = bEnable));
        }

        public void EndFeatureDefinition(TestStatus status)
        {
            base.BeginInvoke((Action)delegate
            {
                this.pbTestsExecution.Style = ProgressBarStyle.Blocks;
                this.lblTestExecutionMessage.Text = "FEATURE DEFINITION - process completed";
            });
        }

        public void EndTest(string testId, string testName, TestStatus status)
        {
            base.BeginInvoke(new Action(() => this.lblTestExecutionMessage.Text = testName + " - test completed"));
        }

        public override IController GetController()
        {
            return this._controller;
        }

        private void InitializeComponent()
        {
            this.components = new Container();
            this.gbTestExecutionInformation = new GroupBox();
            this.btnClear = new Button();
            this.tbOrganizationAddress = new TextBox();
            this.lblOrganizationAddress = new Label();
            this.lblOrganizationName = new Label();
            this.tbOrganizationName = new TextBox();
            this.lblOperatorName = new Label();
            this.tbOperatorName = new TextBox();
            this.gbDutInformation = new GroupBox();
            this.tbProductName = new TextBox();
            this.lblproductName = new Label();
            this.btnClearDeviceInformation = new Button();
            this.lblOtherInformation = new Label();
            this.tbOtherInformation = new TextBox();
            this.lblModel = new Label();
            this.tbModel = new TextBox();
            this.lblBrand = new Label();
            this.tbBrand = new TextBox();
            this.setupPageToolTip = new ToolTip(this.components);
            this.gbRunTest = new GroupBox();
            this.btnDatasheetReport = new Button();
            this.btnDoCReport = new Button();
            this.tbLog = new TextBox();
            this.lblProgress = new Label();
            this.btnReport = new Button();
            this.lblTestExecutionMessage = new Label();
            this.pbTestsExecution = new ProgressBar();
            this.btnRun = new Button();
            this.gbResponsible = new GroupBox();
            this.btnClearMemberInfo = new Button();
            this.tbMemberAddress = new TextBox();
            this.tbMemberName = new TextBox();
            this.lblMemberAddress = new Label();
            this.lblMemberName = new Label();
            this.gbTestExecutionInformation.SuspendLayout();
            this.gbDutInformation.SuspendLayout();
            this.gbRunTest.SuspendLayout();
            this.gbResponsible.SuspendLayout();
            base.SuspendLayout();
            this.gbTestExecutionInformation.Controls.Add(this.btnClear);
            this.gbTestExecutionInformation.Controls.Add(this.tbOrganizationAddress);
            this.gbTestExecutionInformation.Controls.Add(this.lblOrganizationAddress);
            this.gbTestExecutionInformation.Controls.Add(this.lblOrganizationName);
            this.gbTestExecutionInformation.Controls.Add(this.tbOrganizationName);
            this.gbTestExecutionInformation.Controls.Add(this.lblOperatorName);
            this.gbTestExecutionInformation.Controls.Add(this.tbOperatorName);
            this.gbTestExecutionInformation.Dock = DockStyle.Top;
            this.gbTestExecutionInformation.Location = new Point(0, 0xcb);
            this.gbTestExecutionInformation.Name = "gbTestExecutionInformation";
            this.gbTestExecutionInformation.Size = new Size(0x34a, 0x8f);
            this.gbTestExecutionInformation.TabIndex = 20;
            this.gbTestExecutionInformation.TabStop = false;
            this.gbTestExecutionInformation.Text = "Test Execution Information";
            this.btnClear.Anchor = AnchorStyles.Right | AnchorStyles.Top;
            this.btnClear.Location = new Point(0x2f9, 0x72);
            this.btnClear.Name = "btnClear";
            this.btnClear.Size = new Size(0x4b, 0x17);
            this.btnClear.TabIndex = 0x18;
            this.btnClear.Text = "Clear";
            this.setupPageToolTip.SetToolTip(this.btnClear, "Clear tests execution information");
            this.btnClear.UseVisualStyleBackColor = true;
            this.btnClear.Click += new EventHandler(this.btnClear_Click);
            this.tbOrganizationAddress.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.tbOrganizationAddress.Location = new Point(0xa6, 0x47);
            this.tbOrganizationAddress.Multiline = true;
            this.tbOrganizationAddress.Name = "tbOrganizationAddress";
            this.tbOrganizationAddress.ScrollBars = ScrollBars.Vertical;
            this.tbOrganizationAddress.Size = new Size(0x24d, 0x42);
            this.tbOrganizationAddress.TabIndex = 0x17;
            this.lblOrganizationAddress.AutoSize = true;
            this.lblOrganizationAddress.Location = new Point(6, 0x4a);
            this.lblOrganizationAddress.Name = "lblOrganizationAddress";
            this.lblOrganizationAddress.Size = new Size(160, 13);
            this.lblOrganizationAddress.TabIndex = 11;
            this.lblOrganizationAddress.Text = "Executing Organization Address:";
            this.lblOrganizationName.AutoSize = true;
            this.lblOrganizationName.Location = new Point(6, 0x30);
            this.lblOrganizationName.Name = "lblOrganizationName";
            this.lblOrganizationName.Size = new Size(150, 13);
            this.lblOrganizationName.TabIndex = 9;
            this.lblOrganizationName.Text = "Executing Organization Name:";
            this.tbOrganizationName.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.tbOrganizationName.Location = new Point(0xa6, 0x2d);
            this.tbOrganizationName.Name = "tbOrganizationName";
            this.tbOrganizationName.Size = new Size(0x24d, 20);
            this.tbOrganizationName.TabIndex = 0x16;
            this.lblOperatorName.AutoSize = true;
            this.lblOperatorName.Location = new Point(6, 0x16);
            this.lblOperatorName.Name = "lblOperatorName";
            this.lblOperatorName.Size = new Size(0x6a, 13);
            this.lblOperatorName.TabIndex = 7;
            this.lblOperatorName.Text = "Test Operator Name:";
            this.tbOperatorName.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.tbOperatorName.Location = new Point(0xa6, 0x13);
            this.tbOperatorName.Name = "tbOperatorName";
            this.tbOperatorName.Size = new Size(0x24d, 20);
            this.tbOperatorName.TabIndex = 0x15;
            this.gbDutInformation.Controls.Add(this.tbProductName);
            this.gbDutInformation.Controls.Add(this.lblproductName);
            this.gbDutInformation.Controls.Add(this.btnClearDeviceInformation);
            this.gbDutInformation.Controls.Add(this.lblOtherInformation);
            this.gbDutInformation.Controls.Add(this.tbOtherInformation);
            this.gbDutInformation.Controls.Add(this.lblModel);
            this.gbDutInformation.Controls.Add(this.tbModel);
            this.gbDutInformation.Controls.Add(this.lblBrand);
            this.gbDutInformation.Controls.Add(this.tbBrand);
            this.gbDutInformation.Dock = DockStyle.Top;
            this.gbDutInformation.Location = new Point(0, 0x4d);
            this.gbDutInformation.Name = "gbDutInformation";
            this.gbDutInformation.Size = new Size(0x34a, 0x7e);
            this.gbDutInformation.TabIndex = 10;
            this.gbDutInformation.TabStop = false;
            this.gbDutInformation.Text = "Device Under Test Information";
            this.tbProductName.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.tbProductName.Location = new Point(0xa6, 0x13);
            this.tbProductName.Name = "tbProductName";
            this.tbProductName.Size = new Size(0x24d, 20);
            this.tbProductName.TabIndex = 11;
            this.lblproductName.AutoSize = true;
            this.lblproductName.Location = new Point(6, 0x16);
            this.lblproductName.Name = "lblproductName";
            this.lblproductName.Size = new Size(0x4e, 13);
            this.lblproductName.TabIndex = 0x12;
            this.lblproductName.Text = "Product Name:";
            this.btnClearDeviceInformation.Anchor = AnchorStyles.Right | AnchorStyles.Top;
            this.btnClearDeviceInformation.Location = new Point(0x2f9, 0x5e);
            this.btnClearDeviceInformation.Name = "btnClearDeviceInformation";
            this.btnClearDeviceInformation.Size = new Size(0x4b, 0x17);
            this.btnClearDeviceInformation.TabIndex = 0x11;
            this.btnClearDeviceInformation.Text = "Clear";
            this.setupPageToolTip.SetToolTip(this.btnClearDeviceInformation, "Clear device information");
            this.btnClearDeviceInformation.UseVisualStyleBackColor = true;
            this.btnClearDeviceInformation.Click += new EventHandler(this.btnClearDeviceInformation_Click);
            this.lblOtherInformation.AutoSize = true;
            this.lblOtherInformation.Location = new Point(7, 100);
            this.lblOtherInformation.Name = "lblOtherInformation";
            this.lblOtherInformation.Size = new Size(0x5b, 13);
            this.lblOtherInformation.TabIndex = 15;
            this.lblOtherInformation.Text = "Other Information:";
            this.tbOtherInformation.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.tbOtherInformation.Location = new Point(0xa6, 0x61);
            this.tbOtherInformation.Name = "tbOtherInformation";
            this.tbOtherInformation.ScrollBars = ScrollBars.Vertical;
            this.tbOtherInformation.Size = new Size(0x24d, 20);
            this.tbOtherInformation.TabIndex = 14;
            this.lblModel.AutoSize = true;
            this.lblModel.Location = new Point(6, 0x4a);
            this.lblModel.Name = "lblModel";
            this.lblModel.Size = new Size(0x27, 13);
            this.lblModel.TabIndex = 9;
            this.lblModel.Text = "Model:";
            this.tbModel.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.tbModel.Location = new Point(0xa6, 0x47);
            this.tbModel.Name = "tbModel";
            this.tbModel.ReadOnly = true;
            this.tbModel.Size = new Size(0x24d, 20);
            this.tbModel.TabIndex = 13;
            this.lblBrand.AutoSize = true;
            this.lblBrand.Location = new Point(7, 0x30);
            this.lblBrand.Name = "lblBrand";
            this.lblBrand.Size = new Size(0x26, 13);
            this.lblBrand.TabIndex = 7;
            this.lblBrand.Text = "Brand:";
            this.tbBrand.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.tbBrand.Location = new Point(0xa6, 0x2d);
            this.tbBrand.Name = "tbBrand";
            this.tbBrand.ReadOnly = true;
            this.tbBrand.Size = new Size(0x24d, 20);
            this.tbBrand.TabIndex = 12;
            this.gbRunTest.Controls.Add(this.btnDatasheetReport);
            this.gbRunTest.Controls.Add(this.btnDoCReport);
            this.gbRunTest.Controls.Add(this.tbLog);
            this.gbRunTest.Controls.Add(this.lblProgress);
            this.gbRunTest.Controls.Add(this.btnReport);
            this.gbRunTest.Controls.Add(this.lblTestExecutionMessage);
            this.gbRunTest.Controls.Add(this.pbTestsExecution);
            this.gbRunTest.Controls.Add(this.btnRun);
            this.gbRunTest.Dock = DockStyle.Fill;
            this.gbRunTest.Location = new Point(0, 0x15a);
            this.gbRunTest.Name = "gbRunTest";
            this.gbRunTest.Size = new Size(0x34a, 0xde);
            this.gbRunTest.TabIndex = 0x16;
            this.gbRunTest.TabStop = false;
            this.gbRunTest.Text = "Conformance";
            this.btnDatasheetReport.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
            this.btnDatasheetReport.Enabled = false;
            this.btnDatasheetReport.Location = new Point(0x139, 0xbb);
            this.btnDatasheetReport.Name = "btnDatasheetReport";
            this.btnDatasheetReport.Size = new Size(0x9f, 0x1a);
            this.btnDatasheetReport.TabIndex = 3;
            this.btnDatasheetReport.Text = "Generate Feature List";
            this.btnDatasheetReport.UseVisualStyleBackColor = true;
            this.btnDatasheetReport.Click += new EventHandler(this.btnDatasheetReport_Click);
            this.btnDoCReport.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
            this.btnDoCReport.Enabled = false;
            this.btnDoCReport.Location = new Point(6, 0xbb);
            this.btnDoCReport.Name = "btnDoCReport";
            this.btnDoCReport.Size = new Size(0x9a, 0x1a);
            this.btnDoCReport.TabIndex = 1;
            this.btnDoCReport.Text = "Generate DoC";
            this.btnDoCReport.UseVisualStyleBackColor = true;
            this.btnDoCReport.Click += new EventHandler(this.btnDoCReport_Click);
            this.tbLog.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Top;
            this.tbLog.Location = new Point(6, 0x77);
            this.tbLog.Multiline = true;
            this.tbLog.Name = "tbLog";
            this.tbLog.ScrollBars = ScrollBars.Vertical;
            this.tbLog.ReadOnly = true;
            this.tbLog.Size = new Size(830, 0x41);
            this.tbLog.TabIndex = 5;
            this.lblProgress.Anchor = AnchorStyles.Right | AnchorStyles.Top;
            this.lblProgress.Location = new Point(0x2a2, 0x4a);
            this.lblProgress.Name = "lblProgress";
            this.lblProgress.Size = new Size(0xa2, 13);
            this.lblProgress.TabIndex = 4;
            this.lblProgress.TextAlign = ContentAlignment.TopRight;
            this.btnReport.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
            this.btnReport.Enabled = false;
            this.btnReport.Location = new Point(0xa6, 0xbb);
            this.btnReport.Name = "btnReport";
            this.btnReport.Size = new Size(0x8d, 0x1a);
            this.btnReport.TabIndex = 2;
            this.btnReport.Text = "Generate Test Report";
            this.btnReport.UseVisualStyleBackColor = true;
            this.btnReport.Click += new EventHandler(this.btnReport_Click);
            this.lblTestExecutionMessage.AutoSize = true;
            this.lblTestExecutionMessage.Location = new Point(6, 0x4a);
            this.lblTestExecutionMessage.Name = "lblTestExecutionMessage";
            this.lblTestExecutionMessage.Size = new Size(0, 13);
            this.lblTestExecutionMessage.TabIndex = 2;
            this.pbTestsExecution.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.pbTestsExecution.Location = new Point(6, 90);
            this.pbTestsExecution.Name = "pbTestsExecution";
            this.pbTestsExecution.Size = new Size(830, 0x17);
            this.pbTestsExecution.TabIndex = 10;
            this.btnRun.Image = Resources.RunAll;
            this.btnRun.ImageAlign = ContentAlignment.TopCenter;
            this.btnRun.Location = new Point(6, 0x1d);
            this.btnRun.Name = "btnRun";
            this.btnRun.Size = new Size(0x9a, 0x1a);
            this.btnRun.TabIndex = 0;
            this.btnRun.Text = "Start Conformance Test";
            this.btnRun.TextImageRelation = TextImageRelation.ImageBeforeText;
            this.btnRun.UseVisualStyleBackColor = true;
            this.btnRun.Click += new EventHandler(this.btnRun_Click);
            this.gbResponsible.Controls.Add(this.btnClearMemberInfo);
            this.gbResponsible.Controls.Add(this.tbMemberAddress);
            this.gbResponsible.Controls.Add(this.tbMemberName);
            this.gbResponsible.Controls.Add(this.lblMemberAddress);
            this.gbResponsible.Controls.Add(this.lblMemberName);
            this.gbResponsible.Dock = DockStyle.Top;
            this.gbResponsible.Location = new Point(0, 0);
            this.gbResponsible.Name = "gbResponsible";
            this.gbResponsible.Size = new Size(0x34a, 0x4d);
            this.gbResponsible.TabIndex = 1;
            this.gbResponsible.TabStop = false;
            this.gbResponsible.Text = "Responsible Member";
            this.btnClearMemberInfo.Anchor = AnchorStyles.Right | AnchorStyles.Top;
            this.btnClearMemberInfo.Location = new Point(0x2f9, 0x2d);
            this.btnClearMemberInfo.Name = "btnClearMemberInfo";
            this.btnClearMemberInfo.Size = new Size(0x4b, 0x17);
            this.btnClearMemberInfo.TabIndex = 4;
            this.btnClearMemberInfo.Text = "Clear";
            this.btnClearMemberInfo.UseVisualStyleBackColor = true;
            this.btnClearMemberInfo.Click += new EventHandler(this.btnClearMemberInfo_Click);
            this.tbMemberAddress.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.tbMemberAddress.Location = new Point(0xa6, 0x2f);
            this.tbMemberAddress.Name = "tbMemberAddress";
            this.tbMemberAddress.Size = new Size(0x24d, 20);
            this.tbMemberAddress.TabIndex = 3;
            this.tbMemberName.Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top;
            this.tbMemberName.Location = new Point(0xa6, 20);
            this.tbMemberName.Name = "tbMemberName";
            this.tbMemberName.Size = new Size(0x24d, 20);
            this.tbMemberName.TabIndex = 2;
            this.lblMemberAddress.AutoSize = true;
            this.lblMemberAddress.Location = new Point(9, 0x30);
            this.lblMemberAddress.Name = "lblMemberAddress";
            this.lblMemberAddress.Size = new Size(0x59, 13);
            this.lblMemberAddress.TabIndex = 1;
            this.lblMemberAddress.Text = "Member Address:";
            this.lblMemberName.AutoSize = true;
            this.lblMemberName.Location = new Point(9, 0x17);
            this.lblMemberName.Name = "lblMemberName";
            this.lblMemberName.Size = new Size(0x4f, 13);
            this.lblMemberName.TabIndex = 0;
            this.lblMemberName.Text = "Member Name:";
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.Controls.Add(this.gbRunTest);
            base.Controls.Add(this.gbTestExecutionInformation);
            base.Controls.Add(this.gbDutInformation);
            base.Controls.Add(this.gbResponsible);
            base.Name = "ConformanceTestPage";
            base.Size = new Size(0x34a, 0x238);
            this.gbTestExecutionInformation.ResumeLayout(false);
            this.gbTestExecutionInformation.PerformLayout();
            this.gbDutInformation.ResumeLayout(false);
            this.gbDutInformation.PerformLayout();
            this.gbRunTest.ResumeLayout(false);
            this.gbRunTest.PerformLayout();
            this.gbResponsible.ResumeLayout(false);
            this.gbResponsible.PerformLayout();
            base.ResumeLayout(false);
        }

        public void Log(string entry)
        {
            base.BeginInvoke(new Action(() => this.tbLog.AppendText(entry)));
        }

        private void OnDeviceInformationReceived(string manufacturer, string model, string firmwareVersion, string serial, string hardwareId)
        {
            base.BeginInvoke((Action)delegate
            {
                this.tbModel.Text = model;
                this.tbBrand.Text = manufacturer;
            });
        }

        public void ReportDocumentCreationCompleted()
        {
            MessageBox.Show("Report saved", "Operation completed", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
        }

        public void ReportFeatureDefinitionCompleted(bool finished)
        {
            base.BeginInvoke((Action)delegate
            {
                this.pbTestsExecution.Visible = false;
                this.pbTestsExecution.Style = ProgressBarStyle.Blocks;
                if (finished)
                {
                    this.lblTestExecutionMessage.Text = "Feature definition process FAILED. No tests to run were defined";
                }
                else
                {
                    this.lblTestExecutionMessage.Text = "Feature definition process stopped.";
                }
                this.SwitchToIdle();
            });
        }

        public void ReportProgress(int done, int total, int failed)
        {
            base.BeginInvoke((Action)delegate
            {
                this.lblProgress.Text = string.Format("{0} of {1} done, {2} failed", done, total, failed);
                this.pbTestsExecution.Value = done;
            });
        }

        public void ReportTestSuiteCompleted(bool preliminaryPassed, int passed, int failed, bool completedNormally)
        {
            base.BeginInvoke((Action)delegate
            {
                this.pbTestsExecution.Visible = false;
                if (completedNormally)
                {
                    string str = "Conformance Testing " + (((failed == 0) && preliminaryPassed) ? "PASSED" : "FAILED");
                    this.lblTestExecutionMessage.Text = str + ". Details are available at the Diagnostic tab.";
                    this.Log(string.Format("{0} ({1} passed, {2} failed)", str, passed, failed));
                }
                else
                {
                    this.lblTestExecutionMessage.Text = "Test execution stopped";
                }
                this.SwitchToIdle();
                if (completedNormally)
                {
                    MessageBox.Show(this.FindForm(), "Tests completed", "Done", MessageBoxButtons.OK);
                }
            });
        }

        private void SwitchToIdle()
        {
            this.IsReportGeneratorsEnabled = this._reportEnabled;
            this.btnDoCReport.Enabled = this._docEnabled;
            this.btnRun.Enabled = true;
            this._testRunning = false;
            this.btnRun.Text = "Start Conformance Test";
            this.btnRun.Image = Resources.RunAll;
        }

        public override void SwitchToState(TestTool.GUI.Enums.ApplicationState state)
        {
            Action method = null;
            Action action2 = null;
            Action action3 = null;
            switch (state)
            {
                case TestTool.GUI.Enums.ApplicationState.Idle:
                    if (method == null)
                    {
                        method = () => this.EnableControls(true);
                    }
                    base.Invoke(method);
                    return;

                case TestTool.GUI.Enums.ApplicationState.TestRunning:
                case TestTool.GUI.Enums.ApplicationState.TestPaused:
                case TestTool.GUI.Enums.ApplicationState.DiscoveryRunning:
                case TestTool.GUI.Enums.ApplicationState.CommandRunning:
                    if (action2 == null)
                    {
                        action2 = () => this.EnableControls(false);
                    }
                    base.Invoke(action2);
                    return;

                case TestTool.GUI.Enums.ApplicationState.ConformanceTestRunning:
                    if (action3 == null)
                    {
                        action3 = () => this.BeginTests();
                    }
                    base.Invoke(action3);
                    return;
            }
        }

        private bool TryToGetPdfFileName(string ext, string filter, out string fileName)
        {
            SaveFileDialog dialog = new SaveFileDialog
            {
                DefaultExt = ext,
                CheckPathExists = true,
                OverwritePrompt = false,
                Filter = filter
            };
            DialogResult result = dialog.ShowDialog();
            fileName = dialog.FileName;
            return (result == DialogResult.OK);
        }

        private bool ValidateFields()
        {
            List<string> messages = new List<string>();
            TextBox first = null;
            Action<TextBox, Label> action = delegate (TextBox tb, Label lbl)
            {
                if (string.IsNullOrEmpty(tb.Text))
                {
                    messages.Add(string.Format("Field \"{0}\" must be filled", lbl.Text.TrimEnd(new char[] { ':' })));
                    if (first == null)
                    {
                        first = tb;
                    }
                }
            };
            action(this.tbMemberName, this.lblMemberName);
            action(this.tbMemberAddress, this.lblMemberAddress);
            action(this.tbProductName, this.lblproductName);
            if (messages.Count > 0)
            {
                base.ShowPrompt(string.Join(Environment.NewLine, messages.ToArray()), "Required information is missing");
                first.Focus();
            }
            return (messages.Count == 0);
        }

        private bool ValidateTestSettings()
        {
            DeviceEnvironment deviceEnvironment = ContextController.GetDeviceEnvironment();
            bool flag = string.IsNullOrEmpty(deviceEnvironment.TestSettings.EventTopic) || string.IsNullOrEmpty(deviceEnvironment.TestSettings.TopicNamespaces);
            if (flag)
            {
                base.ShowPrompt("Topic (with namespace) for Events tests not defined at the Management page", "Necessary settings missing");
            }
            return !flag;
        }

        public string Brand
        {
            get
            {
                return this.tbBrand.Text;
            }
            set
            {
                this.tbBrand.Text = value;
            }
        }

        internal ConformanceTestController Controller
        {
            get
            {
                return this._controller;
            }
        }

        private bool IsReportGeneratorsEnabled
        {
            get
            {
                return this._isReportGeneratorsEnabled;
            }
            set
            {
                this._isReportGeneratorsEnabled = value;
                this.btnReport.Enabled = value;
                this.btnDatasheetReport.Enabled = value;
            }
        }

        public string MemberAddress
        {
            get
            {
                return this.tbMemberAddress.Text;
            }
            set
            {
                this.tbMemberAddress.Text = value;
            }
        }

        public string MemberName
        {
            get
            {
                return this.tbMemberName.Text;
            }
            set
            {
                this.tbMemberName.Text = value;
            }
        }

        public string Model
        {
            get
            {
                return this.tbModel.Text;
            }
            set
            {
                this.tbModel.Text = value;
            }
        }

        public string OnvifProductName
        {
            get
            {
                return this.tbProductName.Text;
            }
            set
            {
                this.tbProductName.Text = value;
            }
        }

        public string OperatorName
        {
            get
            {
                return this.tbOperatorName.Text;
            }
            set
            {
                this.tbOperatorName.Text = value;
            }
        }

        public string OrganizationAddress
        {
            get
            {
                return this.tbOrganizationAddress.Text;
            }
            set
            {
                this.tbOrganizationAddress.Text = value;
            }
        }

        public string OrganizationName
        {
            get
            {
                return this.tbOrganizationName.Text;
            }
            set
            {
                this.tbOrganizationName.Text = value;
            }
        }

        public string OtherInformation
        {
            get
            {
                return this.tbOtherInformation.Text;
            }
            set
            {
                this.tbOtherInformation.Text = value;
            }
        }
    }
}

